package com.sdp.th.db.th_eq_alarm_smoke_log.service.impl;

import java.math.BigDecimal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sdp.th.db.th_alarm_count.service.IThAlarmCountService;
import com.sdp.th.db.th_eq_alarm_smoke_log.mapper.ThEqAlarmSmokeLogMapper;
import com.sdp.th.db.th_eq_alarm_smoke_log.service.IThEqAlarmSmokeLogService;
import com.sdp.th.db.th_eq_info.service.IThEqInfoService;
import com.sdp.th.entity.ThEqAlarmSmokeLog;
import com.sdp.th.entity.ThEqInfo;
import com.sdp.th.utils.ThConstants;

/**
 * <p>
 * 烟感报警日志 服务实现类
 * </p>
 *
 * @author zsp
 * @since 2025-04-18
 */
@Service
public class ThEqAlarmSmokeLogServiceImpl extends ServiceImpl<ThEqAlarmSmokeLogMapper, ThEqAlarmSmokeLog> implements IThEqAlarmSmokeLogService {

	@Autowired
	private IThEqInfoService iThEqInfoService;
	
	@Autowired
	private IThAlarmCountService iThAlarmCountService;
	
	@Override
	public void verifySmokeAlarm(ThEqAlarmSmokeLog smokeLog) {
		
		ThEqInfo eqInfo = iThEqInfoService.queryEqInfoByNo(smokeLog.getDeviceNo());
		
		if(eqInfo!=null) {
			smokeLog.setDeviceName(eqInfo.getDeviceName());
			smokeLog.setDeviceRoom(eqInfo.getDeviceRoom());
			smokeLog.setDeviceRegion(eqInfo.getDeviceRegion());
			smokeLog.setOrgNo(eqInfo.getOrgNo());
		}
		
		save(smokeLog);
		iThAlarmCountService.setAlarmSmokeCount(BigDecimal.ONE);
	}

	@Override
	public int needHandleAlarmCount() {
		LambdaQueryWrapper<ThEqAlarmSmokeLog> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(ThEqAlarmSmokeLog::getAlarmAction, ThConstants.报警处理_未处理.getCode());
		return count(queryWrapper);
	}

}
